home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Sample Code / Graphics 2D / QuickDraw FX / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  5.7 KB  |  262 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        menu.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: EL    
  7.  
  8.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 08/2000        JM                Carbonized, non-Carbon code is commented out
  20.                                             for demonstration purposes.
  21.                 7/13/1999    KG                Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25.  
  26. #include "FX.h"
  27. #include <Menus.h>
  28. #include <Resources.h>
  29. #include <ToolUtils.h>
  30. #include <Devices.h>
  31. #include <Fonts.h>
  32.  
  33. enum {
  34.     appleID = 128,
  35.     fileID = 129,
  36.     exID = 130,
  37.     srcID = 131
  38. };
  39.  
  40. enum {
  41.     quitItem = 1
  42. };
  43.  
  44. #define    WWIDTH        420
  45. #define    WHEIGHT        200
  46.  
  47. //#define WLEFT        (((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - WWIDTH) / 2)
  48. //#define WTOP        (((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - WHEIGHT) / 2)
  49.  
  50.  
  51. void setUpMenus()
  52. {
  53.     Handle        menuHandle;
  54.     
  55.     if ((menuHandle = GetNewMBar( 128 )) == nil)
  56.         ExitToShell();
  57.         
  58.     SetMenuBar( menuHandle );
  59.     AppendResMenu( GetMenu( appleID ), 'DRVR' );
  60.         
  61.     DrawMenuBar();
  62.     ReleaseResource( menuHandle );
  63. }
  64.  
  65. void adjustMenus()
  66. {
  67.     int        i;
  68.  
  69.     //EnableItem( GetMenuHandle( fileID ), quitItem );
  70.     EnableMenuItem( GetMenuHandle( fileID ), quitItem );
  71.     
  72.     for (i = 1; i <= pixelAverageID; i++)
  73.         setMenuItem( GetMenuHandle( exID ), i, (i == gCurrentExample / 10) );
  74.     
  75.     setMenuItem( GetMenuHandle( exID ), customID + 1, (customID == gCurrentExample / 10) );
  76. }
  77.  
  78. void setMenuItem( MenuHandle menu, int itemNum, Boolean enabled )
  79. {
  80.     /*if (enabled)
  81.         //CheckItem( menu, itemNum, true );
  82.         CheckMenuItem( menu, itemNum, true );
  83.     else
  84.         //CheckItem( menu, itemNum, false );
  85.         CheckMenuItem( menu, itemNum, false );*/
  86.     CheckMenuItem( menu, itemNum, enabled );
  87. }
  88.  
  89. void handleMenu( long mSelect )
  90.  
  91. {
  92.     int            menuID = HiWord( mSelect );
  93.     int            menuItem = LoWord( mSelect );
  94.     //GrafPtr        savePort;
  95.     //Str255        name;
  96.     long        ticks;
  97.  
  98.     switch (menuID)
  99.     {
  100.         case appleID:
  101.             if (menuItem == 1)
  102.                 doAboutBox();
  103.             else
  104.             {
  105.                 /*GetPort( &savePort );
  106.                 GetMenuItemText( GetMenu( appleID ), menuItem, name );
  107.                 OpenDeskAcc( name );
  108.                 SetPort( savePort );*/
  109.             }
  110.             break;
  111.             
  112.         case fileID:
  113.             if (menuItem)
  114.                 ExitToShell();
  115.             break;
  116.             
  117.         case exID:
  118.             if (menuItem == 10)
  119.                 menuItem--;
  120.  
  121.             if (menuItem == gCurrentExample / 10)
  122.                 break;
  123.             
  124.             if (menuItem == 9)
  125.                 resetItems();
  126.                 
  127.             gCurrentExample = (menuItem * 10) + 1;
  128.             drawExampleName();
  129.             drawSourceImage();
  130.             
  131.             ticks = drawFXImage();
  132.             drawTime( ticks );
  133.             drawAllItems();
  134.             break;
  135.             
  136.         case srcID:
  137.             createOffscreen( menuItem );
  138.             drawSourceImage();
  139.             
  140.             ticks = drawFXImage();
  141.             drawTime( ticks );
  142.             break;
  143.     }
  144.     
  145.     HiliteMenu( 0 );
  146. }
  147.  
  148. void doAboutBox()
  149. {
  150.     int                col, row;
  151.     int                width, height;
  152.     WindowPtr        window;
  153.     CIconHandle        cicn;
  154.     Rect            rect;
  155.     RGBColor        color;
  156.     BitMap            bitMap;
  157.     int                left, top;
  158.  
  159.     cicn = GetCIcon( 128 );
  160.     HPurge( (Handle)cicn );
  161.     
  162.     GetQDGlobalsScreenBits(&bitMap);
  163.     left = (((bitMap.bounds.right - bitMap.bounds.left) - WWIDTH) / 2);
  164.     top = (((bitMap.bounds.bottom - bitMap.bounds.top) - WHEIGHT) / 2);
  165.  
  166.     //SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  167.     SetRect( &rect, left, top, left + WWIDTH, top + WHEIGHT );
  168.     window = NewCWindow( 0L, &rect, "\p", true, plainDBox, (WindowPtr)-1L, false, 0L );                            
  169.     //SetPort( window );
  170.     SetPortWindowPort( window );
  171.         
  172.     TextFont( kFontIDGeneva );
  173.     TextMode( srcOr );
  174.     
  175.     color.red = color.green = color.blue = 8700;
  176.     RGBForeColor( &color );
  177.         
  178.     //rect = window->portRect;
  179.     GetPortBounds(GetWindowPort(window), &rect);
  180.     InsetRect( &rect, 1, 1 );
  181.     PaintRect( &rect );
  182.     
  183.     width = 32 * 6;
  184.     height = width;
  185.     
  186.     SetRect( &rect, 3, 3, width + 3, height + 3 );
  187.     PlotCIcon( &rect, cicn );
  188.  
  189.     ForeColor( blackColor );
  190.  
  191.     for (row = 6; row < height; row += 6)
  192.     {
  193.         MoveTo( rect.left, rect.top + row );
  194.         LineTo( rect.left + width, rect.top + row );
  195.     }
  196.     
  197.     for (col = 6; col < width; col += 6)
  198.     {
  199.         MoveTo( rect.left + col, rect.top );
  200.         LineTo( rect.left + col, rect.top + height );
  201.     }
  202.     
  203.     col = width + 15;
  204.     row = 35;
  205.     
  206.     TextFont( kFontIDTimes );
  207.     TextSize( 36 );
  208.     
  209.     color.blue = 0xffff;
  210.     color.red = color.green = 0;
  211.     RGBForeColor( &color );    
  212.     drawMyString( col, &row, 30, "\pQuickDraw™" );
  213.     
  214.     color.blue = 0x9fff;
  215.     RGBForeColor( &color );
  216.     drawMyString( col + 45, &row, -5, "\pFX" );
  217.     
  218.     TextFont( kFontIDGeneva );
  219.     TextSize( 9 );
  220.     ForeColor( whiteColor );
  221.     
  222.     col += 10;
  223.     
  224.     drawMyString( col + 115, &row, 25, "\pVersion 1.0" );
  225.     drawMyString( col, &row, 20, "\pBrought to you by Edgar Lee." );
  226.     
  227.     drawMyString( col, &row, 13, "\pFor any suggestions or comments," );
  228.     drawMyString( col, &row, 13, "\pplease write to edgar@apple.com" );
  229.     drawMyString( col, &row, 20, "\por appleLink EDGAR." );
  230.     
  231.     drawMyString( col, &row, 15, "\p© 1992-1999 Apple Computer, Inc." );
  232.     drawMyString( col, &row, 25, "\pAll rights reserved." );
  233.     
  234.     TextFont( kFontIDTimes );
  235.     TextSize( 36 );
  236.     
  237.     color.green = 0x8fff;
  238.     color.red = color.blue = 0;
  239.     RGBForeColor( &color );
  240.     drawMyString( col + 125, &row, 0, "\pDTS" );
  241.     
  242.     while (!Button());
  243.     
  244.     DisposeWindow( window );
  245. }
  246.  
  247. void drawMyString( int col, int *row, int increment, Str255 string)
  248. {
  249.     RGBColor    color;
  250.     
  251.     GetForeColor( &color );
  252.     
  253.     ForeColor( blackColor );
  254.     MoveTo( col + 2, *row + 2 );
  255.     DrawString( string );
  256.     
  257.     RGBForeColor( &color );
  258.     MoveTo( col, *row );
  259.     DrawString( string );
  260.     
  261.     *row += increment;
  262. }